package netty.rpc.framework.client.controller;

import lombok.extern.slf4j.Slf4j;
import netty.rpc.framework.api.model.User;
import netty.rpc.framework.api.service.Calculator;
import netty.rpc.framework.api.service.UserService;
import netty.rpc.framework.core.netty.annotation.RPCReference;
import netty.rpc.framework.core.netty.consumer.ChannelProvider;
import netty.rpc.framework.core.netty.consumer.ClientTransport;
import netty.rpc.framework.core.netty.factory.SingletonFactory;
import netty.rpc.framework.core.netty.registry.ZKUtils;
import netty.rpc.framework.core.netty.transport.client.NettyCilent;
import netty.rpc.framework.core.netty.transport.protocol.RPCRequest;
import org.apache.curator.framework.CuratorFramework;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
public class Controller {

    @RPCReference
    private Calculator calculator;

    @RPCReference
    private UserService userService;

    public Calculator getCalculator() {
        return calculator;
    }

    public UserService getUserService() {
        return userService;
    }

    @GetMapping("netty/test")
    public String test(){
        System.out.println("calculator add = "+calculator.add(13, 15));
        return "ok";
    }

    @GetMapping("netty/users")
    public String testUsers(){
        User user1 = userService.getUser(1);
        System.out.println(user1.toString());
        System.out.println("---------------");
        User user2 = userService.getUser(-1);
        System.out.println(user2);
        return "ok";
    }

    public void setCalculator(Calculator calculator) {
        this.calculator = calculator;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }


}
